package com.lxl.demo01.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lxl.demo01.domain.DoAlert;
import com.lxl.demo01.service.IDoAlertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController  // 注释掉这个，启动后不会访问这个
@RequestMapping("/doalerts")
public class DoAlertController2 {
    @Autowired
    private IDoAlertService iDoAlertService;

    // 页面层-查询所有数据
    @GetMapping
    public List<DoAlert> getAll() {
        // 调用业务层来执行
        return iDoAlertService.list();
    }

    // 页面层-查询单个数据
    @GetMapping("{id}")
    public DoAlert getById(@PathVariable Long id) {
        return iDoAlertService.getById(id);
    }

    // 页面层-添加一条数据
    @PostMapping
    public Boolean save(@RequestBody DoAlert doAlert) {
        // 调用业务层来执行
        return iDoAlertService.save(doAlert);
    }

    // 页面层-修改一条数据
    @PutMapping
    public Boolean update(@RequestBody DoAlert doAlert) {
        // 调用业务层来执行
        return iDoAlertService.updateById(doAlert);
    }

    // 页面层-删除一条数据(通过id)
    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Long id) {
        // 调用业务层来执行
        return iDoAlertService.removeById(id);
    }

    // 页面层-分页查询
    @GetMapping("{currentPage}/{pageSize}")
    public IPage<DoAlert> getPage(@PathVariable int currentPage, @PathVariable int pageSize) {
        // 调用业务层中自定义的方法来执行
        return iDoAlertService.getPage(currentPage, pageSize);
    }
}
